{extend name="public/base" /}
{block name="pjax_container"}
<?php
    $titleTypeName = '积分奖扣添加(专审事件)';
?>
<style>


    .content-header > .breadcrumb > li {
        color: #999;
    }

    .content-header > .breadcrumb > .active {
        color: #666;
    }

    .content-header {
        height: 51px;

    }

    .box-primary {
        border-top-color: #ecf0f5 !important;
        border-top-width: 16px;

    }

    .delete-one {
        background-color: ff4141 !important;
        margin-left: 15px;
        border-radius: 6px;
    }

    .sreachs {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 7px 15px;
    }

    .nav-tabs-custom {
        margin-top: 16px;
    }

    .modal-content {
        margin-top: 150px;
        width: 800px;
        height: 692px;

    }

    .modal-body {
        padding: 27px;
        height: 570px;
        display: flex;
    }

    .modal-right {
        flex: 1;
        height: 523px;
        border: 1px solid #eee;
        margin-left: 30px;
    }

    .modal-right > h4 {
        width: 100%;
        display: flex;
        justify-content: space-around;
    }

    .form-control {
        border-radius: 6px;
    }

    .table-body {
        width: 750px;
        height: 470px;
        margin-top: 10px;
        border-radius: 6px;
        background-color: #eee;
    }

    .table-left {
        margin-right: 2%;
        width: 49%;
        height: 100%;
        float: left;
        border: 1px solid #eee;
        background-color: #fff;
    }

    .table-right {
        width: 49%;
        height: 100%;
        border: 1px solid #eee;
        float: left;
        background-color: #fff;
    }

    .layui-tree-entry {
        height: 100%;
        width: 100%;
        padding-right: 10px;
        line-height: 24px;

    }

    .table-right > p {
        text-align: center;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        font-size: 14px;
    }

    .table-right > h4 {
        text-align: center;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        font-size: 14px;

    }

    .table-right > p > span {
        text-align: center;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        font-size: 14px;
        width: 80%;
        display: inline-block;
        letter-spacing: 1px;

    }

    .tab-content {
        border-bottom: 0px solid #f3f3f3;
    }

    .box-footer {
        display: none;
        border-top: 0px solid #f4f4f4;
    }

    .submits {
        padding: 8px 20px;
        border: none;
        outline: none;
    }
    /* 快捷设置样式 */
    .fast_set{
        margin-top: 20px;
    }
    .fast_set_title{
        font-size: 14px;
        line-height: 34px;
        text-align: center;
    }
    .tab-pane .things-tips-parent{
        position:relative;
    }
    .tab-pane .things-tips{
        display: none!important;
        position: absolute;
        right: 0px;
        top: 0px;
        display: inline-block;
    }
    .tab-pane .things-tips-parent:hover .things-tips{
        display: block!important;
    }
    .tab-pane .things-tips .content_tips{
        display: none;
        position: absolute;
        top: 0;
        width: 350px;
        line-height: 18px;
        background: #fff;
        padding: 8px;
        border: 1px solid #dadada;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        color: rgba(0, 0, 0, 0.65);
        border-radius: 4px;
    }
    #myModal_multiple .modal-content{
        width: 1053px !important;
    }
</style>
<section class="content-header">
    <ol class="breadcrumb">
        <li>积分管理</li>
        <li>我提交的奖扣</li>
        <li class="active">{$titleTypeName}</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal layui-form" method="POST" action="/{$Think.MODULE_NAME}/{$Think.CONTROLLER_NAME}/{$Think.ACTION_NAME}" onsubmit="return false">
                <input type="hidden" name="id" value="{$info.id|default=0}"/>
                <input name="check_opinion" class="check_opinion" value="" type="hidden">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="pull-right"><a href="javascript:history.back(-1)" class="btn btn-sm" style="padding:10px 2px;"><i class="fa fa-list"></i> 返回</a></li>
                    </ul>
                    <div class="tab-content-wrap">
                        <div class="tab-content">
                            <div class="tab-pane active">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">事件编号:</label>
                                    <div class="col-sm-4 thing_num" style="line-height:33px;">
                                        1
                                    </div>
                                    <input type="hidden" value="0" class="even_number" name="number[]">
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">事件</label>
                                    <div class="col-sm-4 things-tips-parent">
                                        <input type="text" name="" value="" is_piece="" style="border-radius: 6px;"
                                               class="form-control things_check" placeholder="事件选择"/>
                                        <input type="hidden" class="things_check_id" name="event_id[]" value="" integral_a_end="" integral_a_start="" integral_b_end="" integral_b_start="" >
                                        <div class="things-tips"></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">描述</label>
                                    <div class="col-sm-4">
                                        <textarea name="event_desc[]" class="form-control" style="height: 100px;border-radius: 6px;"></textarea>
                                    </div>
                                </div>
                                <div style="text-align: right;width: 50%">
                                    <div class="btn-group add_user" style="margin-left: 20px;">
                                        <div type="submit" class="btn btn-info pull-right add_take">添加参与人</div>
                                    </div>
                                </div>
                                <div class="form-group" style="margin-top: 20px;">
                                    <label class="col-sm-2 control-label">初审人:</label>
                                    <div class="col-sm-2">
                                        <select name="first_check_user_id" lay-filter="first_check_user_id" lay-verify="">
                                            <option class="locked_first_check_top" value="">选择初审人</option>
                                            
<!--                                            <option value="qt" class="check_others_people">选择其他</option>-->
                                            
                                        </select>
                                        <!-- <input type="hidden" name="first_check_user_id" value="{$info.first_check_user_id??''}"> -->
                                        <!-- <input name="first_check_user_name" style="border-radius: 6px;" class="form-control classname" value="{$info.first_check_user_id?$users[$info.first_check_user_id]['name']??'' : ''}" placeholder="初审人" autocomplete="off"/> -->
                                    </div>

                                    <label class="col-sm-1 control-label">终审人:</label>
                                    <div class="col-sm-2">
                                        <select name="last_check_user_id" lay-filter="last_check_user_id" lay-verify="">
                                            <option class="locked_last_check_top" value="">选择终审人</option>
                                            
<!--                                            <option value="qt" class="check_others_people">选择其他</option>-->
                                        </select>
                                        <!-- <input name="last_check_user_name" style="border-radius: 6px;" class="form-control classname" value="{$info.last_check_user_id?$users[$info.last_check_user_id]['name']??'' : ''}" placeholder="终审人" limits_b="" autocomplete="off"/>
                                        <input type="hidden" name="last_check_user_id" value="{$info.last_check_user_id??''}"> -->
                                    </div>
                                </div>
                                <div class="fast_set">
                                    <div class="form-group user_item">
                                        <label class="col-sm-2 control-label" ></label>
                                        <div class="col-sm-1">
                                            <div class="fast_set_title">快捷设置</div> 
                                        </div>
                                        <label class="col-sm-1 control-label">A分</label>
                                        <div class="col-sm-1">
                                            <input class="form-control" data-name="integral_a" type="number" name="" value="">
                                        </div>
                                        <label class="col-sm-1 control-label">B分</label>
                                        <div class="col-sm-1">
                                            <input class="form-control" data-name="integral_b" type="number" name="" value="">
                                        </div>
                                        <div class="fast_set_isPiece" style="display: none">
                                            <label class="col-sm-1 control-label">计件</label>
                                            <div class="col-sm-1">
                                                <input class="form-control" data-name="piece_rate" type="number" min="1" value="1" name=""> 
                                            </div>
                                        </div>
                                        
                                    </div>
                                </div> 
                                <div class="user_list" style="margin-top: 10px;">
                                </div>
                            </div>
                        </div>
                        <div class="btn-group" style="display: block; width: 170px; margin: 0 auto;">
                            <div class="btn btn-info next" style="margin-left: 20px;">下一步</div>
                        </div>

                    </div>
                    <div class="box-footer">
                        {include file="form/input" title="主题" name="theme"/}
                        {include file="form/input_textarea" title="备注" name="desc"/}
                        
                        <div class="check">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">奖扣时间:</label>
                                <div class="col-sm-2">
                                    <input type="text" name="prize_buckle_time" style="border-radius: 6px;"
                                           class="form-control timepicker">
                                </div>
                                <label class="col-sm-1 control-label">抄送人:</label>
                                <div class="col-sm-2">
                                    <input name="copy_user_name" style="border-radius: 6px;"
                                           class="form-control classname" value="" placeholder="抄送人"/>
                                    <input type="hidden" name="copy_user_id" value="{$info.copy_user_id??''}">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-2"></div>
                        <div class="col-sm-8">
                            <div class="btn-group pull-right">
                                <div class="btn btn-info pull-left last" style="margin-right: 20px;">上一步</div>
                                <button type="submit" id="audit_sub_submit" data="{$user_id}" class="btn btn-info pull-right" data-loading-text="&lt;i class='fa fa-spinner fa-spin  '&gt;&lt;/i&gt; 提交">提交
                                </button>
                                <button class="submits" style="display: none"></button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</section>
<!-- 快捷设置人员分值 -->
<script>
    $(".tab-content").on("input propertychange",".fast_set input",function(){
        let value = $(this).val();
        let name = $(this).attr("data-name");
        let list = $(this).parents(".tab-pane").find(".user_list ."+name);
        if(list.length > 0){
            for (let i = 0; i < list.length; i++) {
                list.eq(i).val(value);
            }
        }
    })
</script>
<!-- 下拉选择框 -->
<script>
    layui.use('form', function(){
        var form = layui.form;
        form.render(); 
    });
    //删除参与人
    $("body").on('click', '.cancel_item', function () {
        $(this).parents('.user_item').remove()
    });
    //阻止回车键表单提交
    $("body").on("keypress","input",function(e){
        if(e.keyCode==13){
            e.preventDefault();
        }
    })
</script>
<!-- 点击下一步上一步判定 -->
<script>
    $('.next').click(function () {
        var things_check = $(".tab-content .things_check_id");
        for (let i = 0; i < things_check.length; i++) {
            // things_check.eq(i).val();
            if (things_check.eq(i).val() == "") {
                layui.layer.msg("事件不能为空");
                return false;
            }
        };
        var user_list_item = $(".tab-content .user_list").find(".user_item");
        if (user_list_item.length == 0) {
            layui.layer.msg("参与人不能为空");
            return false;
        }else{
            for (let i = 0; i < user_list_item.length; i++) {
                var a = user_list_item.eq(i).find(".integral_a").val();
                var b = user_list_item.eq(i).find(".integral_b").val();
                if (a == "" && b == "") {
                    layui.layer.msg("参与人分值不能为空");
                    return false;
                }
            }
        }

        if(first_id == "" || last_id == ""){
            layui.layer.msg("初审人或者终审人不能为空");
            return false;
        }
        if (first_id == last_id) {
            layui.layer.msg("初审人和终审人不能为同一个人");
            return false;
        }
        $(".box-footer").show();
        $(".tab-content-wrap").hide();
        //判断是否为多事件添加主题和时间
        let now_time = new Date();
        let year = now_time.getFullYear();
        let month = now_time.getMonth()+1;
        let day = now_time.getDate();
        let title;
        if($(".tab-content .tab-pane").length > 1){
            title = now_time;
        }else{
            title = $(".tab-content .tab-pane .things_check").val();
            title = year+'-'+month+'-'+day + '-' + title;
        }
        $(".box-footer input[name='theme']").val(title);
        let timepicker = year+'-'+month+'-'+day;
        $(".box-footer .timepicker").val(timepicker);
    });
    $('.last').click(function () {
        $(".box-footer").hide();
        $(".tab-content-wrap").show();
    })
</script>

<!-- 监听是否为超标事件 -->
<script>
    $(".user_list").on("change",".integral_a,.integral_b",function(){
        var return_array = check_is_not_over();
        // console.log(return_array);
        //第一个参数大于零表示超标
        if(last_a_max == -1 && last_b_max == -1){
            $(".locked_last_check").remove();
            $(".locked_last_check_top").after(luser);
        }else{
            $(".locked_last_check").remove();
        }
        //重新渲染下拉框
        layui.use('form', function(){
            var form = layui.form;
            form.render(); 
        });
    })
    //判断是否超标方法Math.abs(aaa);
    function check_is_not_over(){
        var a_max_num = 0;
        var b_max_num = 0;
        var a_is_over = 0;
        var b_is_over = 0;
        var return_array = [];
        for (let i = 0; i < $(".user_list .integral_a").length; i++) {
            var now_a_num = $(".user_list .integral_a").eq(i).val();
            if( Math.abs(now_a_num) > a_max_num){
                a_max_num = Math.abs(now_a_num);
            }
            if( now_a_num  - a_min < 0 || a_max - now_a_num  < 0){
                a_is_over ++;
            }
        }
        for (let i = 0; i < $(".user_list .integral_b").length; i++) {
            var now_b_num = $(".user_list .integral_b").eq(i).val();
            if( Math.abs(now_b_num) > b_max_num){
                b_max_num = Math.abs(now_b_num);
            }
            if( now_b_num  - b_min < 0 || b_max - now_b_num  < 0){
                b_is_over ++;
            }
        }
        if(a_is_over > 0 && b_is_over > 0){
            return_array = [a_max_num , b_max_num]
        }else{
            if (a_is_over > 0) {
                return_array = [  a_max_num , -1]; 
            }else{
                if(b_is_over > 0){
                    return_array = [  a_max_num , -1]; 
                }else{
                    return_array = [  -1 , -1 ];
                }
            }
        }
        return return_array;
    }
</script>

<!-- 弹框样式引入 -->
<link rel="stylesheet" href="__STATIC__/global/an_tree_css/an_tree_css.css">
<script>
    // 时间选择器
    layui.use(['tree', 'laydate'], function () {
        var tree = layui.tree;
        var laydate = layui.laydate;
        var nowtime = "{:date('Y-01-01 H:i:s',time())}";
        var end_time = laydate.render({
            elem: '.timepicker'
            // , min: nowtime //0天前
            , max: 7 //7天后
            // , type: 'datetime'//样式
        });
        var apply_end_time = laydate.render({
            elem: '.apply_end_time'
            // , min: nowtime //0天前
            , max: 7 //7天后
            // , type: 'datetime' //样式
        });
    });
</script>

<!-- Modal 弹出层重写 事件选择  -->
<div class="modal fade" id="myModal_things" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel_things">事件选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left">
                    <div class="modal-left-title" style="margin-bottom: 20px;">
                        <div class="input-group">
                            <input name="search_user_name" type="text" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info search_btn" type="button"
                                        style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;">
                                    <span class="glyphicon glyphicon-search"></span>
                                </button>
                            </span>
                        </div>
                    </div>
                    <div class="input-group table-body">
                        <div class="table-left">
                            <div class="an_tree">

                            </div>
                        </div>
                        <div class="table-right">
                            <div class="an_tree_list">
                                <!-- <div class="an_list_title">

                                </div> -->
                                <div class="an_list_con">
                                    <!-- <div class="an_list_item">
                                        <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                                        <div class="item_info">
                                            <span class="name">专审事件锁定测试</span>
                                            <span>工作类事件 / 日常工作类事件</span>
                                        </div>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary popups_submit">确认</button>
            </div>
        </div>
    </div>
    <!-- <div class="content_tips">
        <p>事件分类：<span>工作类事件/ 日常工作类事件</span></p>
        <p>分值范围：<span>A分:0 ~ 0 B分:100 ~ 200 产值:0 ~ 0</span></p>
        <p>事件属性：<span>专审事件 计件事件</span></p>
        <p><p>备注信息：</p><p><span>暂无备注信息</span></p></p>
    </div> -->
</div>
<!-- 提示操作 事件选择  -->
<script>
    $("#myModal_things").on("mouseenter", ".an_list_item", function () {
        var i = $("#myModal_things .an_list_con .an_list_item").index(this);
        $("#myModal_things .content_tips").eq(i).show();
    });
    $("#myModal_things").on("mouseleave", ".an_list_item", function () {
        $("#myModal_things .content_tips").hide();
    });
    $('#myModal_things').mousemove(function (e) {
        var xx = e.originalEvent.x;//e.originalEvent.x; || e.originalEvent.layerX || 0
        var yy = e.originalEvent.y;//e.originalEvent.y; || e.originalEvent.layerY || 0;
        $("#myModal_things .content_tips").css("left", xx);
        $("#myModal_things .content_tips").css("top", yy);
        // console.log(xx);
        // console.log(yy);
    });
</script>
<!-- 单选弹窗操作 事件选择  -->
<script>
    var things_data;
    var now_item_name;//名字输入框
    var now_item_id;//id输入框
    var now_item_fast_set;//快捷设置计件节点
    var now_item_things_tips;//事件提示节点
    var a_min = ""
    var a_max = ""
    var b_min = "";
    var b_max = "";
    var fuser = "";//初审人下拉框
    var luser = "";//终审人下拉框
    //确认按钮   事件选择完成后要添加初审人终审人下拉框
    $('#myModal_things .popups_submit').click(function (e) {
        $('#myModal_things').modal('hide');
        var checked = $(".an_tree_list").find(".list_item_check");
        now_item_name.val(checked.attr("data_name"));
        now_item_name.attr("is_piece", checked.attr("is_piece"));
        now_item_id.val(checked.attr("data_id"));
        //获取提示信息
        var i = $("#myModal_things .an_list_con .an_list_item").index(checked);//选中第几个元素
        var check_tips = $("#myModal_things .content_tips").eq(i).prop("outerHTML");//选中所选元素的提示信息
        now_item_things_tips.html(check_tips);
        now_item_things_tips.find(".content_tips").css("left", 0).css("top", 0).show();
        //判断是否为计件事件，快捷设置里面添加计件
        if(checked.attr("is_piece") == 0){
            now_item_fast_set.hide();
        }else{
            now_item_fast_set.show();
        };
        //事件分值赋值
        a_min = checked.attr("integral_a_start");
        a_max = checked.attr("integral_a_end");
        b_min = checked.attr("integral_b_start");
        b_max = checked.attr("integral_b_end");
        //事件分值赋值
        now_item_id.attr("integral_a_start", checked.attr("integral_a_start"));
        now_item_id.attr("integral_a_end", checked.attr("integral_a_end"));
        now_item_id.attr("integral_b_start", checked.attr("integral_b_start"));
        now_item_id.attr("integral_b_end", checked.attr("integral_b_end"));
        //初审人和终审人赋值
        var sort = $("#myModal_things .an_list_con .an_list_item").index($("#myModal_things .an_list_con .list_item_check"));
        
        $.each(things_data[sort].fuser, function (index, value) {
            fuser += '<option class="locked_first_check" value="'+index+'">'+value+'</option>';
        });

        $(".locked_first_check").remove();
        $(".locked_first_check_top").after(fuser);
        
        $.each(things_data[sort].luser, function (index, value) {
            luser += '<option class="locked_last_check" value="'+index+'">'+value+'</option>';
        });

        $(".locked_last_check").remove();
        $(".locked_last_check_top").after(luser);
        //重新渲染下拉框
        layui.use('form', function(){
            var form = layui.form;
            form.render(); 
        });
        // console.log(luser);
        // console.log(things_data);
    });
    //当弹窗关闭时执行重置弹窗
    $('#myModal_things').on('hidden.bs.modal', function () {
        // 执行一些动作...重置弹窗
        $(".an_tree_list .an_list_con").html("");
        $(".tree_txt_active").removeClass("tree_txt_active");
        $(".an_tree_pack").hide();
        $(".an_tree .fa").removeClass("fa-caret-down").addClass("fa-caret-right");
        $("#myModal_things input[name='search_user_name']").val("");
    });
    // 事件选择
    $('.tab-content').on('focus', '.things_check', function () {
        $('#myModal_things').modal('show');
        now_item_name = $(this);
        now_item_id = $(this).siblings(".things_check_id");//节点
        //快捷设置计件节点
        now_item_fast_set = $(this).parents(".tab-pane").find(".fast_set_isPiece");
        now_item_things_tips = $(this).parents(".tab-pane").find(".things-tips");
    });
</script>
<!-- 树结构js操作 事件选择  -->
<script>
    $("#myModal_things .an_tree").on("click", ".fa", function () {
        $(this).toggleClass("fa-caret-down");
        $(this).toggleClass("fa-caret-right");
        $(this).parents(".an_tree_set").eq(0).children(".an_tree_pack").toggle();
    });
    $("#myModal_things").on("click", ".an_tree_txt,.search_btn", function () {
        $(".an_tree").find(".tree_txt_active").removeClass("tree_txt_active");
        $(this).addClass("tree_txt_active");
        var department_id = $(this).attr("data_id");
        // var department_name = $(this).html();
        var user_name = $("#myModal_things input[name='search_user_name']").val();
        // console.log(user_name);
        $.ajax({
            type: 'get',
            url: "{:url('base/base_event_child')}",
            data: {'id': department_id, 'search_name': user_name, 'is_check' : 1},
            dataType: "json",
            success: function (data) {
                things_data = data;
                // console.log(data);
                // return false;
                var content = '';
                var content_tips = '';
                $.each(data, function (index, value) {
                    if (value.is_piece) {
                        var is_piece = '<p>事件属性：<span>计件事件</span></p>';
                    } else {
                        var is_piece = '';
                    }
                    if (value.desc == "") {
                        var desc = '<span>暂无备注信息</span>'
                    } else {
                        var desc = '<span>' + value.desc + '</span>'
                    }
                    content += '<div class="an_list_item" data_id="' + value.id + '" data_name="' + value.name + '" is_piece="' + value.is_piece + '" integral_a_start="'+value.integral_a_start+'" integral_a_end="'+value.integral_a_end+'" integral_b_start="'+value.integral_b_start+'" integral_b_end="'+value.integral_b_end+'"> <div class="item_box item_box_check"><i class="fa fa-check"></i></div> <div class="item_info"> <span class="name">' + value.name + '</span> <span>' + value.show_cate_name + '</span> </div> </div>';
                    content_tips += '<div class="content_tips"> <p>事件分类：<span>' + value.show_cate_name +'</span></p> <p>分值范围：<span>A分:' + value.integral_a_start + ' ~ ' + value.integral_a_end + ' B分:' + value.integral_b_start + ' ~ ' + value.integral_b_end + '</span></p>' + is_piece + '<p><p>备注信息：</p><p>' + desc + '</p></p> </div>'

                });
                $('.an_list_con').html("");
                $('.an_list_con').append(content);
                $("#myModal_things .content_tips").remove();
                $("#myModal_things").append(content_tips);
            }
        })
    });
    $("#myModal_things .an_tree_list").on("click", ".an_list_item", function () {
        $(this).siblings().removeClass("list_item_check");
        $(this).toggleClass("list_item_check")
    })
</script>
<!-- 递归填充目录 事件选择  -->
<script>
    var an_tree = ergodic({$eventList});
    $("#myModal_things .an_tree").append(an_tree);

    function ergodic(data) {
        var content = '';
        // console.log(data);
        $.each(data, function (index, value) {
            if (value.children != "") {
                var children = ergodic(value.children);
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"><i class="fa fa-caret-right"></i></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.name + '</span></div></div><div class="an_tree_pack">' + children + '</div></div>';
            } else {
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.name + '</span></div></div><div class="an_tree_pack"></div></div>';
            }
        });
        return content;
    }
</script>


<!-- Modal 弹出层重写 单选  -->
<div class="modal fade" id="myModal_single" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModal_single">人员选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left">
                    <div class="modal-left-title" style="margin-bottom: 20px;">
                        <div class="input-group">
                            <input name="search_user_name" type="text" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info search_btn" type="button"
                                        style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;">
                                    <span class="glyphicon glyphicon-search"></span>
                                </button>
                            </span>
                        </div>
                    </div>
                    <div class="input-group table-body">
                        <div class="table-left">
                            <div class="an_tree">

                            </div>
                        </div>
                        <div class="table-right">
                            <div class="an_tree_list">
                                <div class="an_list_title">

                                </div>
                                <div class="an_list_con">
                                    <!-- <div class="an_list_item">
                                        <div class="item_info">
                                            <span class="name">aaa</span>/
                                            <span>88</span>/
                                            <span>部门</span>
                                        </div>
                                        <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary popups_submit">确认</button>
            </div>
        </div>
    </div>

</div>
<!-- 单选弹窗操作  -->
<script>
    var last_a_max = -1;//终审人a分筛选
    var last_b_max = -1;//终审人b分筛选
    var first_id = "";//初审人id
    var last_id = "";//终审人id
    var csr_id = "";//抄送人id
    var now_item_name;//标识选择初审，终审，抄送
    var now_item_id;//id输入框
    var user_type;
    var pcqt_people = [];//排除其他人员数组
    //确认按钮
    $('#myModal_single .popups_submit').click(function (e) {
        $('#myModal_single').modal('hide');
        var checked = $(".an_tree_list").find(".list_item_check");
        if (now_item_name == 1) {
            first_id = checked.attr("user_id");
            $(".locked_first_check_top").html(checked.attr("user_name"));
            $(".locked_first_check_top").val(first_id);
            $(".locked_first_check_top").attr("selected",true);
            $(".check_others_people").attr("selected",false);
            
        }else{
            if (now_item_name == 2) {
                last_id = checked.attr("user_id");
                $(".locked_last_check_top").html(checked.attr("user_name"));
                $(".locked_last_check_top").val(last_id);
                $(".locked_last_check_top").attr("selected",true);
                $(".check_others_people").attr("selected",false);
            }else{
                cyr_id = checked.attr("user_id");
                now_item_name.val(checked.attr("user_name"));
                now_item_id.val(checked.attr("user_id"));
                now_item_name.attr("limits_b", checked.attr("limits_b"));
            }
        }
        layui.use('form', function(){
            var form = layui.form;
            form.render();
        });
    });
    //当弹窗关闭时执行重置弹窗
    $('#myModal_single').on('hidden.bs.modal', function () {
        // 执行一些动作...重置弹窗
        $(".an_tree_list .an_list_title").html("");
        $(".an_tree_list .an_list_con").html("");
        $(".tree_txt_active").removeClass("tree_txt_active");
        $(".an_tree_pack").hide();
        $(".an_tree .fa").removeClass("fa-caret-down").addClass("fa-caret-right");
        $("#myModal_single input[name='search_user_name']").val("");
    });
    //layui监听下拉框
    layui.use('form', function(){
        var form = layui.form;
        //初审人
        form.on('select(first_check_user_id)', function(data){
            // console.log(data.elem); //得到select原始DOM对象
            // console.log(data.value); //得到被选中的值
            // console.log(data.othis); //得到美化后的DOM对象
            if(data.value == "qt"){
                $(".locked_first_check_top").attr("selected",true);
                $(".check_others_people").attr("selected",false);
                if($(".tab-content .things_check_id").val() == ""){
                    layui.layer.msg("请先选择事件！");
                }else{
                    $('#myModal_single').modal('show');
                    user_type = 1;
                    now_item_name = 1;//标识选择初审，终审，抄送
                    pcqt_people = [];//获取参与人数组
                    pcqt_people.push(csr_id,last_id);//添加抄送人,终审人
                }
            }else{
                $(".locked_first_check_top").attr("selected",false);
                first_id = data.value;//id值
            };
            
            form.render();
            return false;
        });
        //终审人
        form.on('select(last_check_user_id)', function(data){
            // console.log(data.elem); //得到select原始DOM对象
            // console.log(data.value); //得到被选中的值
            // console.log(data.othis); //得到美化后的DOM对象
            if(data.value == "qt"){
                $(".locked_last_check_top").attr("selected",true);
                $(".check_others_people").attr("selected",false);
                if($(".tab-content .things_check_id").val() == ""){
                    layui.layer.msg("请先选择事件！");
                }else{
                    $('#myModal_single').modal('show');
                    user_type = 2;
                    now_item_name = 2;//标识选择初审，终审，抄送
                    pcqt_people = hqcyr_array();//获取参与人数组
                    pcqt_people.push(csr_id,first_id);//添加抄送人,终审人
                    //终审人超标事件筛选分数
                    var return_array = check_is_not_over();
                    last_a_max = return_array[0];
                    last_b_max = return_array[1];
                }
            }else{
                $(".locked_last_check_top").attr("selected",false);
                //先选参与人后下拉框不能选相关终审人
                var cyr_array = hqcyr_array();
                if($.inArray(data.value, cyr_array) >= 0){
                    last_id = "";
                    $(".locked_last_check_top").attr("selected",true);
                    $(data.elem).attr("selected",false);
                    layui.layer.msg("参与人不能成为终审人！");
                }else{
                    last_id = data.value;
                }
            };
            form.render();
            return false;
        });        
    });
    // 抄送人
    $("input[name='copy_user_name']").focus(function () {
        $('#myModal_single').modal('show');
        now_item_name = $(this);
        now_item_id = $("input[name='copy_user_id']");//节点
        user_type = 2;
        pcqt_people = hqcyr_array();//获取参与人数组
        pcqt_people.push(last_id,first_id);//添加终审人,初审人
        //不是终审人不筛选分值
        last_a_max = -1;
        last_b_max = -1;
    });
    //获取参与人数组
    function hqcyr_array(){
        var now_item_ids = [];
        for (let i = 0; i < $(".user_list").find(".user_item").length; i++) {
            now_item_ids.push($(".user_list").find(".user_item").eq(i).find(".cyr_id").val());
        }
        return now_item_ids;
    }
</script>
<!-- 树结构js操作 单选  -->
<script>
    $("#myModal_single .an_tree").on("click", ".fa", function () {
        $(this).toggleClass("fa-caret-down");
        $(this).toggleClass("fa-caret-right");
        $(this).parents(".an_tree_set").eq(0).children(".an_tree_pack").toggle();
    });
    $("#myModal_single").on("click", ".an_tree_txt,.search_btn", function () {
        $(".an_tree").find(".tree_txt_active").removeClass("tree_txt_active");
        $(this).addClass("tree_txt_active");
        var department_id = $(this).attr("data_id");
        var department_name = $(this).html();
        var user_name = $("#myModal_single input[name='search_user_name']").val();
        // console.log(user_name);
        $.ajax({
            type: 'get',
            url: "{:url('base/base_department_per')}",
            data: {
                'department_id': department_id,
                'first_check_user_id': pcqt_people,
                'last_check_user_id': pcqt_people,
                'user_type': user_type,
                'user_name': user_name,
                'a_max': last_a_max,
                'b_max': last_b_max,
            },
            dataType: "json",
            success: function (data) {
                // var json = JSON.parse(data);
                // console.log(data);
                var content = '';
                $.each(data, function (index, value) {
                    if (value.limits == undefined) {
                        var limits = 0;
                    } else {
                        var limits = value.limits.b;
                    }
                    content += '<div class="an_list_item" user_name="' + value.name + '" user_id="' + value.id + '" limits_b="' + limits + '"><div class="item_info"><span class="name">' + value.name + '</span>/<span>' + value.job_number + '</span>/<span>' + value.department_name + '</span></div><div class="item_box "><i class="fa fa-check"></i></div></div>'
                });
                $('.an_list_con').html("");
                $('.an_list_con').append(content);
                $('.an_list_title').html(department_name + data.length + '人');
            }
        })
    });
    $("#myModal_single .an_tree_list").on("click", ".an_list_item", function () {
        $(this).siblings().removeClass("list_item_check");
        $(this).toggleClass("list_item_check")
    })
</script>
<!-- 递归填充目录 单选  -->
<script>
    var an_tree = ergodic({$department});
    $("#myModal_single .an_tree").append(an_tree);
    function ergodic(data) {
        var content = '';
        $.each(data, function (index, value) {
            if (value.children != "") {
                var children = ergodic(value.children);
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"><i class="fa fa-caret-right"></i></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack">' + children + '</div></div>';
            } else {
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack"></div></div>';
            }
        });
        return content;
    }
</script>


<!-- Modal 弹出层重写 多选   -->
<div class="modal fade" id="myModal_multiple" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel10">人员选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left">
                    <div class="modal-left-title" style="margin-bottom: 20px;">
                        <div class="input-group">
                            <input type="text" name="search_user_name" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info search_btn" type="button"
                                        style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;"><span
                                        class="glyphicon glyphicon-search"></span></button>
                            </span>
                        </div>
                    </div>
                    <div class="input-group table-body">
                        <div class="table-left">
                            <div class="an_tree">

                            </div>
                        </div>
                        <div class="table-right">
                            <div class="an_tree_list">
                                <div class="an_list_title">

                                </div>
                                <div class="an_list_con">
                                    <!-- <div class="an_list_item">
                                        <div class="item_info">
                                            <span class="name">aaa</span>/
                                            <span>88</span>/
                                            <span>部门</span>
                                        </div>
                                        <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-right">
                    <div class="multiresult_header">
                        <div>已选择<span class="number">0</span>个</div>
                        <div class="header_clear">清空</div>
                    </div>
                    <div class="multiresult_list">
                        <!-- <div class="an_list_item">
                            <div class="item_info">
                                <span class="name">aaa</span>/
                                <span>88</span>/
                                <span>部门</span>
                            </div>
                            <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                        </div> -->

                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary popups_submit" id="submit2">确认</button>
            </div>
        </div>
    </div>
</div>
<!-- 多选弹窗操作  -->
<script>
    var now_item_multiple = "";//名字输入框
    var input_name = "";
    var is_piece = "";
    $(".tab-content").on("click", ".add_take", function () {
        is_piece = $(this).parents(".tab-pane").find(".things_check").attr("is_piece");
        if (is_piece == "") {
            layui.layer.msg("请先选择事件");
        } else {
            $('#myModal_multiple').modal('show');
            now_item_multiple = $(this).parents(".tab-pane").find(".user_list");
            input_num = $(this).parents(".tab-pane").find(".even_number").val();
            new_right_add();
        }
    });
    $(".add_message_push").click(function () {
        $('#myModal_multiple').modal('show');
        now_item_multiple = $(this).parents(".tab-pane").find(".user_list");
        input_num = $(this).parents(".tab-pane").find(".even_number").val();
        // new_right_add();
        pcqt_people=[];
        pcqt_people.push(last_id);//添加终审人
        pcqt_people.push(csr_id);//添加抄送人
    });
    //确认按钮
    $('#myModal_multiple .popups_submit').click(function (e) {
        $('#myModal_multiple').modal('hide');
        var check_all = $("#myModal_multiple .multiresult_list .an_list_item");
        var item_ids = [];
        for (let i = 0; i < check_all.length; i++) {
            item_ids.push(check_all.eq(i).attr("user_id"));
        }
        var now_item = now_item_multiple.find(".user_item");
        for (let i = 0; i < now_item.length; i++) {
            var cyr_id = now_item.eq(i).find(".cyr_id").val();
            if ($.inArray(cyr_id, item_ids) < 0) {
                now_item.eq(i).remove();
            }
        }
        var now_item_ids = [];
        for (let i = 0; i < now_item_multiple.find(".user_item").length; i++) {
            now_item_ids.push(now_item_multiple.find(".user_item").eq(i).find(".cyr_id").val());
        }
        var content = "";
        if (is_piece == 1) {
            for (let i = 0; i < check_all.length; i++) {
                var input_value = check_all.eq(i).attr("user_id");
                var input_limits_b = check_all.eq(i).attr("limits_b");
                var input_user_name = check_all.eq(i).attr("user_name");
                var input_user_num = check_all.eq(i).find(".item_info span").eq(1).html();
                var input_apart_name = check_all.eq(i).find(".item_info span").eq(2).html();
                if ($.inArray(input_value, now_item_ids) < 0) {
                    content += '<div class="form-group user_item"> <label class="col-sm-2 control-label">参与人</label> <div class="col-sm-1"><input type="text" name="" value="' + input_user_name + '" disabled style="border-radius: 6px;" value="" class="form-control cyr_name"> <input type="hidden" class="cyr_id" name="user_id[' + input_num + '][]" user_name="' + input_user_name + '" value="' + input_value + '" user_name="' + input_user_name + '" input_user_num="' + input_user_num + '" apart_name="' + input_apart_name + '" limits_b="' + input_limits_b + '"></div> <label class="col-sm-1 control-label">A分</label> <div class="col-sm-1"> <input class="form-control integral_a" type="number" name="integral_a[' + input_num + '][]"> </div>  <label class="col-sm-1 control-label">B分</label> <div class="col-sm-1"> <input class="form-control integral_b" type="number" name="integral_b[' + input_num + '][]"> </div> <label class="col-sm-1 control-label">计件</label> <div class="col-sm-1"> <input class="form-control piece_rate" type="number" min="1" value="1" name="piece_rate[' + input_num + '][]"> </div> <div class="btn-group pull-right" style="float: inherit!important;"> <div class="btn btn-warning cancel_item">移除</div> </div> </div>';
                }
                // content += '<input type="hidden" name="'+input_name+'" user_name="'+input_user_name+'" value="'+input_value+'" user_name="'+input_user_name+'" input_user_num="'+input_user_num+'" apart_name="'+input_apart_name+'" limits_b="'+input_limits_b+'">';
            }
        } else {
            for (let i = 0; i < check_all.length; i++) {
                var input_value = check_all.eq(i).attr("user_id");
                var input_limits_b = check_all.eq(i).attr("limits_b");
                var input_user_name = check_all.eq(i).attr("user_name");
                var input_user_num = check_all.eq(i).find(".item_info span").eq(1).html();
                var input_apart_name = check_all.eq(i).find(".item_info span").eq(2).html();
                // content += '<input type="hidden" name="'+input_name+'" user_name="'+input_user_name+'" value="'+input_value+'" user_name="'+input_user_name+'" input_user_num="'+input_user_num+'" apart_name="'+input_apart_name+'" limits_b="'+input_limits_b+'">';
                if ($.inArray(input_value, now_item_ids) < 0) {
                    content += '<div class="form-group user_item"> <label class="col-sm-2 control-label">参与人</label> <div class="col-sm-1"><input type="text" name="" value="' + input_user_name + '" disabled style="border-radius: 6px;" value="" class="form-control cyr_name"> <input type="hidden" class="cyr_id" name="user_id[]" user_name="' + input_user_name + '" value="' + input_value + '" user_name="' + input_user_name + '" input_user_num="' + input_user_num + '" apart_name="' + input_apart_name + '" limits_b="' + input_limits_b + '"></div> <label class="col-sm-1 control-label">A分</label> <div class="col-sm-1"> <input class="form-control integral_a" type="number" name="integral_a[]"> </div>  <label class="col-sm-1 control-label">B分</label> <div class="col-sm-1"> <input class="form-control integral_b" type="number" name="integral_b[]"> </div> <div class="btn-group pull-right" style="float: inherit!important;"> <div class="btn btn-warning cancel_item">移除</div> </div> </div>';
                }
            }
        }
        now_item_multiple.append(content);
    });
    //当弹窗关闭时执行重置弹窗
    $('#myModal_multiple').on('hidden.bs.modal', function () {
        //执行一些动作...重置弹窗
        $(".an_tree_list .an_list_title").html("");
        $(".an_tree_list .an_list_con").html("");
        $(".tree_txt_active").removeClass("tree_txt_active");
        $(".an_tree_pack").hide();
        $(".an_tree .fa").removeClass("fa-caret-down").addClass("fa-caret-right");
        $("#myModal_multiple input[name='search_user_name']").val("");
        $("#myModal_multiple .header_clear").click();
    });

    //已选择，再进行补充选择时添加右侧选中
    function new_right_add() {
        var input = now_item_multiple.find(".user_item .cyr_id");
        var content = ""
        for (let i = 0; i < input.length; i++) {
            input.eq(i).attr("");
            content += '<div class="an_list_item " user_name="' + input.eq(i).attr("user_name") + '" user_id="' + input.eq(i).attr("value") + '" limits_b="' + input.eq(i).attr("limits_b") + '"><div class="item_info"><span class="name">' + input.eq(i).attr("user_name") + '</span>/<span>' + input.eq(i).attr("input_user_num") + '</span>/<span>' + input.eq(i).attr("apart_name") + '</span></div><div class="item_box "><i class="fa fa-remove"></i></div></div>'
        }
        $("#myModal_multiple .multiresult_list").append(content);
    }
</script>
<!-- 树结构js操作 多选  -->
<script>
    $("#myModal_multiple .an_tree").on("click", ".fa", function () {
        $(this).toggleClass("fa-caret-down");
        $(this).toggleClass("fa-caret-right");
        $(this).parents(".an_tree_set").eq(0).children(".an_tree_pack").toggle();
    });
    //添加中间人员列表
    $("#myModal_multiple").on("click", ".an_tree_txt,.search_btn", function () {
        $(".an_tree").find(".tree_txt_active").removeClass("tree_txt_active");
        $(this).addClass("tree_txt_active");
        var department_id = $(this).attr("data_id");
        var department_name = $(this).html();
        var user_name = $("#myModal_multiple input[name='search_user_name']").val();
        // console.log(user_name);
        $.ajax({
            type: 'get',
            url: "{:url('base/base_department_per')}",
            data: {'department_id': department_id, 'user_name': user_name,'user_type': 0,'last_check_user_id': pcqt_people,},
            dataType: "json",
            success: function (data) {
                // var json = JSON.parse(data);
                // console.log(data);
                var content = '';
                $.each(data, function (index, value) {
                    if (value.limits == undefined) {
                        var limits = 0;
                    } else {
                        var limits = value.limits.b;
                    }
                    content += '<div class="an_list_item" user_name="' + value.name + '" user_id="' + value.id + '" limits_b="' + limits + '"><div class="item_info"><span class="name">' + value.name + '</span>/<span>' + value.job_number + '</span>/<span>' + value.department_name + '</span></div><div class="item_box "><i class="fa fa-check"></i></div></div>'
                });
                $('#myModal_multiple .an_list_con').html("");
                $('#myModal_multiple .an_list_con').append(content);
                $('#myModal_multiple .an_list_title').html('<div>' + department_name + data.length + '人</div><div class="all_item_box"><i class="fa fa-check"></i></div>');
                left_add_active();
                check_all();
            }
        })
    });
    // 选中事件
    $("#myModal_multiple .an_tree_list").on("click", ".an_list_item", function () {
        $(this).toggleClass("list_item_check");
        var ischeck = $(this).attr("class");
        if (ischeck.indexOf("list_item_check") >= 0) {
            add_check();
        } else {
            del_check($(this).attr("user_id"));
        }
        check_all();
    });
    //全选按钮
    $("#myModal_multiple .an_tree_list").on("click", ".all_item_box", function () {
        $(this).toggleClass("all_item_box_check");
        var ischeck = $(this).attr("class");
        var all_item = $("#myModal_multiple .an_tree_list .an_list_item");
        if (ischeck.indexOf("all_item_box_check") >= 0) {
            all_item.addClass("list_item_check");
            add_check();
        } else {
            all_item.removeClass("list_item_check")
            for (let i = 0; i < all_item.length; i++) {
                del_check(all_item.eq(i).attr("user_id"));
            }
        }
        check_all();
    });
    //右侧删除事件
    $("#myModal_multiple .multiresult_list").on("click", ".item_box", function () {
        var user_id = $(this).parents(".an_list_item ").attr("user_id");
        del_check(user_id);
        check_all();
    });
    //右侧清空监听
    $("#myModal_multiple .multiresult_header").on("click", ".header_clear", function () {
        var all_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < all_item.length; i++) {
            del_check(all_item.eq(i).attr("user_id"));
        }
        check_all();
    });

    //全选按钮检测
    function check_all() {
        var all_item_num = $("#myModal_multiple .an_tree_list .an_list_item").length;
        var checked_item_num = $("#myModal_multiple .an_tree_list .list_item_check").length;
        if (all_item_num != 0 && all_item_num == checked_item_num) {
            $("#myModal_multiple .an_tree_list .all_item_box").addClass("all_item_box_check");
        } else {
            $("#myModal_multiple .an_tree_list .all_item_box").removeClass("all_item_box_check");
        }
        ;
        //右侧选中人数统计
        var people_num = $("#myModal_multiple .multiresult_list .an_list_item").length;
        $("#myModal_multiple .multiresult_header .number").html(people_num);
    };

    //添加右侧选中项
    function add_check() {
        var item_ids = [];
        var all_checked_item = $("#myModal_multiple .an_list_con").find(".list_item_check");
        var now_checker_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < now_checker_item.length; i++) {
            item_ids.push(now_checker_item.eq(i).attr("user_id"));
        }
        for (let i = 0; i < all_checked_item.length; i++) {
            var now_id = all_checked_item.eq(i).attr("user_id");
            if ($.inArray(now_id, item_ids) < 0) {
                var new_item = all_checked_item.eq(i).prop("outerHTML");
                new_item = new_item.replace("fa-check", "fa-remove");
                new_item = new_item.replace("list_item_check", "");
                $("#myModal_multiple .multiresult_list").append(new_item);
            }
        }
        // console.log(item_ids);
    }

    //左侧第一次生成时检测是否有选中项
    function left_add_active() {
        var left_item_ids = [];
        var left_checked_item = $("#myModal_multiple .an_list_con .an_list_item");
        var right_checker_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < left_checked_item.length; i++) {
            left_item_ids.push(left_checked_item.eq(i).attr("user_id"));
        }
        for (let i = 0; i < right_checker_item.length; i++) {
            var user_id = right_checker_item.eq(i).attr("user_id");
            if ($.inArray(user_id, left_item_ids) >= 0) {
                $("#myModal_multiple .an_list_con .an_list_item[user_id=" + user_id + "]").addClass("list_item_check");
            }
        }
    }

    //取消选中项
    function del_check(user_id) {
        var left_item_ids = [];
        var right_item_ids = [];
        var left_checked_item = $("#myModal_multiple .an_list_con .an_list_item");
        var right_checker_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < left_checked_item.length; i++) {
            left_item_ids.push(left_checked_item.eq(i).attr("user_id"));
        }
        for (let i = 0; i < right_checker_item.length; i++) {
            right_item_ids.push(right_checker_item.eq(i).attr("user_id"));
        }
        if ($.inArray(user_id, left_item_ids) >= 0) {
            $("#myModal_multiple .an_list_con .an_list_item[user_id=" + user_id + "]").removeClass("list_item_check");
        }
        if ($.inArray(user_id, right_item_ids) >= 0) {
            $("#myModal_multiple .multiresult_list .an_list_item[user_id=" + user_id + "]").remove();
        }
    }
</script>
<!-- 递归填充目录 多选  -->
<script>
    var an_tree = ergodic({$department});
    $("#myModal_multiple .an_tree").append(an_tree);

    function ergodic(data) {
        var content = '';
        $.each(data, function (index, value) {
            if (value.children != "") {
                var children = ergodic(value.children);
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"><i class="fa fa-caret-right"></i></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack">' + children + '</div></div>';
            } else {
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack"></div></div>';
            }
        });
        return content;
    }
</script>


<!-- 拟稿提交按钮触发弹窗_ -->
<script>
    $("#audit_sub_submit").click(function () {
        var check_id = $("input[name='first_check_user_id']").val();
        var now_id = $(this).attr("data");
        if (check_id == now_id) {
            $('#myModal2').modal('show');
            $("#tips_submit").click(function (e) {
                var check_opinion = $("#check_opinion_textarea").val();
                $("#check_opinion").val(check_opinion);
                $('#myModal2').modal('hide');
                $(".submits").click();
            });
        } else {
            $(".submits").click();
        }
        return false;
    });
</script>
<!-- 拟稿提交按钮触发弹窗DOM结构_ -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
    <div class="modal-dialog" role="document">
        <div class="modal-content move" style="height: 282px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel2">提示</h4>
            </div>
            <div class="modal_body" style="width: 100%;padding: 20px;">
                <label style="width: 100%;margin: 0!important;">
                    请填写您的初审意见：
                    <textarea name="check_opinion_textarea" id="check_opinion_textarea" cols="45" rows="5"
                              style="display: block;width: 100%;max-height: 100px; margin:0;padding: 10px;border-radius: 5px;"
                              placeholder="可以输入一千字"></textarea>
                </label>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="tips_submit">确认</button>
            </div>
        </div>
    </div>
</div>
{/block}